# Maintainer: kasper93 <kasper93@gmail.com>

_realname=libdovi
_sourcename=dovi_tool-${_realname}
pkgbase=mingw-w64-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}
pkgver=3.2.0
pkgrel=1
pkgdesc='Library to read and write Dolby Vision metadata (C-API)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url='https://github.com/quietvoid/dovi_tool/tree/main/dolby_vision'
license=('MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-rust"
             "${MINGW_PACKAGE_PREFIX}-cargo-c")
source=("https://github.com/quietvoid/dovi_tool/archive/refs/tags/libdovi-${pkgver}.tar.gz")
sha256sums=('23c339b08bf32b66144b8fe17bf9a39f2dc810a37f081e5bc50207af9ae99922')

prepare() {
  cd "${srcdir}/${_sourcename}-${pkgver}/dolby_vision"

  cargo fetch
}

build() {
  cd "${srcdir}/${_sourcename}-${pkgver}/dolby_vision"

  cargo cbuild \
    --release \
    --frozen \
    --prefix="${MINGW_PREFIX}"
}

check() {
  cd "${srcdir}/${_sourcename}-${pkgver}/dolby_vision"

  cargo test \
    --release \
    --frozen \
    --all-features
}

package() {
  cd "${srcdir}/${_sourcename}-${pkgver}/dolby_vision"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    cargo cinstall \
        --release \
        --frozen \
        --prefix="${MINGW_PREFIX}" \
        --destdir="${pkgdir}"

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
